<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div class="card-body">
        <avue-crud :data="subjectListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   class="avuecrud">
        </avue-crud>
      </div>
    </div>
  </basic-container>
</template>

<script>
  import {getSubjectResultList} from "@/api/subject";
  import {Subject_DIC} from '@/const/dict'

  export default {
    name: "subjectRelease",
    created() {
      var self = this;
      window.subjectResultDetail = self.subjectResultDetail;
      this.getResultList(this.page);
    },
    data() {
      return {
        headerData: {
          title: '课题成果'
        },
        subjectListData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        queryParams:{

        },
        tableoption: {
          page: true,
          menuWidth: 100,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          menu:false,
          column: [
            {
              label: "规划名称",
              prop: "achievementTitle",
              cell: true
            },
            {
              label: "课题名称",
              width: 450,
              prop: "title",
              cell: true,
              search: true,
              searchSpan: 12,
              formatter: function (row, value, label, column) {
                return '<a style="cursor:pointer;" onclick="subjectResultDetail(\'' + row.subjectId + '\')">' + value + '</a>';
              }
            },
            {
              label: "结题时间",
              prop: "publishTime",
              width: 120,
              formatter: function (row, value, label, column) {
                if (row.publishTime != null) {
                  var data = row.publishTime.split(' ');
                  return data[0];
                }
              },
              cell: true
            },
          ]
        },
        tableLoading: false,
        titleLikes: '',
      }
    },
    methods: {
      // 课题征集意见跳转
      subjectOpinionList(row, index) {
        let src = `/subjectOpinionList/detail/${row.subjectId}`;
        this.$router.push({
          path: src
        })
      },
      searchChange(params){
        this.queryParams = Object.assign(this.queryParams, {
          titleLike: params.title
        });
        this.titleLikes= params.title
        this.page.currentPage = 1
        this.getResultList();
      },
      searchReset(){
        this.queryParams = {};
        this.getResultList();
      },
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        var params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        var params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },
      onload(page){
        this.page = page;
        this.getResultList();
      },
      getResultList() {
        let page = this.page;
        let params = this.queryParams;
        getSubjectResultList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
        },params)).then(response => {
          this.subjectListData = response.data.data.records;
          this.page.total = response.data.data.total;
        })
      },
      // 课题详情跳转
      subjectResultDetail(subjectId) {
        let src = `/subject/detail?id=${subjectId}`;
        this.$router.push({
          path: src
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .card-body {
    padding: 10px;
    min-height: 400px;
  }
</style>
<style lang="scss">
  .avuecrud {
    .el-table th, .el-table tr {
      height: 60px;
    }
  }
</style>
